package demo2;

import java.util.*;
import java.util.function.BiConsumer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-05-18
 * Time: 20:16
 */
//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    //当一个接口中只有一个抽象方法的时候，叫做函数式接口
    void test();
}

//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}
public class Test {
    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();
        map.put("aos",5);
        map.put("iso",1);
        map.put("is",6);
        map.put("oas",3);
        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println(s + " "+ integer);
            }
        });
        map.forEach((s, integer) -> System.out.println(s + " "+ integer));
    }
    public static void main5(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("iih");
        list.add("ojsi");
        list.forEach(s-> System.out.println(s));
    }
    public static void main4(String[] args) {
        PriorityQueue<Integer> max = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });
        PriorityQueue<Integer> max2 = new PriorityQueue<>((x,y)->x.compareTo(y));
    }
    public static void main3(String[] args) {
        int a = 1;
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                //捕获的变量一定是没有修改过的，或者是一个常量
                System.out.println("a="+a);
            }
        };
    }
    public static void main2(String[] args) {
        OneParameterNoReturn oneParameterNoReturn = (x)->{
            System.out.println(x);
        };
        OneParameterNoReturn oneParameterNoReturn1 = x -> System.out.println(x);
        MoreParameterNoReturn moreParameterNoReturn = (x, y)-> System.out.println(x + y);
        moreParameterNoReturn.test(10, 20);
        System.out.println("=====");
        NoParameterReturn noParameterReturn = ()->{return 10;};
        NoParameterReturn noParameterReturn1 = ()->10;
        OneParameterReturn oneParameterReturn = x ->{
            return x;
        };
        OneParameterReturn oneParameterReturn1 = x->x*2;

        MoreParameterReturn moreParameterReturn = (x , y) -> {
            return (x+y);
        };
    }
    public static void main1(String[] args) {
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("1234");
            }
        };
        noParameterNoReturn.test();
        System.out.println("===============");

        NoParameterNoReturn noParameterNoReturn1 = ()-> System.out.println("1234");
        noParameterNoReturn1.test();
    }

}
